package com.ray.repository.impl;

import com.ray.entity.Student;
import com.ray.repository.StudentRepository;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@Repository
public class StudentRepositoryImpl implements StudentRepository {

    private static Map<Integer, Student> studentMap;

    static {
        studentMap = new HashMap<>();
        studentMap.put(1, new Student(1,"张三",22));
        studentMap.put(2, new Student(2,"李四",32));
        studentMap.put(3, new Student(3,"王五",12));
    }
    @Override
    public Collection<Student> findAll() {
        return studentMap.values();
    }

    @Override
    public Student findById(Integer id) {
        return studentMap.get(id);
    }

    @Override
    public void saveOrUpdate(Student s) {
        studentMap.put(s.getId(), s);
    }

    @Override
    public void deleteById(Integer id) {
        studentMap.remove(id);
    }
}
